
'use strict';

//app.mountpath  挂接

var express = require('express');

// var app = express(); // the main app
// var admin = express(); // the sub app

// app.get('/', function(req, res) {
//     res.send('Hello World!');
// });

// admin.get('/', function (req, res) {
//   console.log(admin.mountpath); // /admin
//   res.send('Admin Homepage');
// })

// app.use('/admin', admin); // mount the sub app
// 


var app = express(); 
app.get('/', function(req, res) {
    res.send('Hello World!');
});

var admin = express();
admin.get('/', function (req, res) {
  console.log(admin.mountpath); // [ '/adm*n', '/manager' ]
  res.send('Admin Homepage');
})

var secret = express();
//Events
//app.on('mount', callback(parent))
secret.on('mount', function (parent) {
  console.log('secret Mounted 打印信息下面是父');
  console.log(parent); // refers to the parent app
});
secret.get('/', function (req, res) {
  console.log(secret.mountpath); // /secr*t
  res.send('Admin Secret');
});

admin.use('/secr*t', secret); // load the 'secret' router on '/secr*t', on the 'admin' sub app
app.use(['/adm*n', '/manager'], admin); // load the 'admin' router on '/adm*n' and '/manager', on the parent app


var server = app.listen(3000, function() {
    var host = server.address().address;
    var port = server.address().port;

    console.log('Example app listening at http://%s:%s', host, port);
});
